<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Insert title here</title>
		<link rel="stylesheet" href="../../css/global.css">
		<link rel="stylesheet" href="../../css/mytable.css">
		<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
		<link rel="stylesheet" href="" id='bugcss'>
		<script type="text/javascript">
			document.querySelector('#bugcss').href = '../../layuiadmin/style/bug.css?v=1.0&code=' + new Date();
		</script>
	</head>

	<body>
		<div class="warp">
			<div class="layui-container form-main">
				<div class="layui-row main-handle">
					<button onclick="location.href='husbandry_add.html'" class="layui-btn my-btn-blue my-min-width">添加产品批次</button>
					<button onclick="location.href='husbandry_assign.html'" class="layui-btn my-btn-blue my-min-width">指派农事任务</button>
					<button onclick="location.href='product_batche/product_batche_list.html'" class="layui-btn my-btn-blue my-min-width">已完成农事列表</button>

				</div>
				<div class="layui-row main-title">
					产品批次管理
				</div>
				<div>
					<div class="widget-body no-padding">
						<table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
							<thead>
								<tr>
								</tr>
								<tr>
									<th>序号</th>
									<th>作物名称</th>
									<th>作物批次</th>
									<th>种植面积</th>
									<th>采收时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</div>
			</div>
	</body>

</html>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script src="../../js/qrcode.min.js"></script>
<script src="../../js/mytable.js"></script>

<script type="text/javascript">
	//	layui.use('laypage', function() {
	//		var laypage = layui.laypage;
	//		//执行一个laypage实例
	//		laypage.render({
	//			elem: 'demo2',
	//			count: 100,
	//			theme: '#1E9FFF'
	//		});
	//	});

	layui.use(['layer'], function() {
		var layer = layui.layer;
	});
	var userStatus = showDictSelect("status", "userStatus", true);

	var pers = checkPermission();

	var example;

	function init() {
		example =
			$('#dt-table').DataTable({
				//              "pagingType":"simple_numbers ",
				// 'paging':false,
				"searching": false,
				"processing": false,
				"serverSide": true,
				"language": {
					"url": "/js/plugin/datatables/Chinese.lang"
				},
				"ajax": {
					"url": "/productBatchess",
					"type": "get",
					"data": function(d) {
						// console.log(d)
						d.status = $('#status').val();

					},
					"error": function(xhr, textStatus, errorThrown) {
						var msg = xhr.responseText;
					}
				},

				// "dom": "<'layui-box layui-laypage layui-laypage-molv' p>",
				// "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
				"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer pages'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10 pageslist' p v>>",
				"columns": [{
						"data": "id",
						"defaultContent": ""
					},
					{
						"data": "productName",
						"defaultContent": ""
					},
					{
						"data": "productBatch",
						"defaultContent": ""
					},
					{
						"data": "area",
						"defaultContent": ""
					},
					{
						"data": "recoverydate",
						"defaultContent": ""
					},
					{
						"data": "",
						"defaultContent": "",
						"orderable": false,

						"render": function(data, type, row) {
							var id = row['id'];
							var href = "husbandry_edit.html?id=" + id;
							var record = buttonRecord('husbandry_record.html?id=' + id, "sys:user:add", pers);
							var edit = buttonEdit(href, "sys:user:add", pers);
							var del = buttonDel(id, "", pers);
							var scan = buttonScan(id, "", pers);
							return record + edit + del + scan;
						}
					}
				],
				"order": [
					[0, "desc"],
					[1, "asc"]
				]
			});
	}

	function del(id) {
		layer.confirm('确定要删除该产品批次数据吗？此操作不可逆,请慎重!!!', {
			btn: ['确定', '取消']
		}, function() {
			$.ajax({
				type: 'delete',
				url: '/productBatchess/' + id,
				success: function(data) {
					example.ajax.reload();
					layer.msg("删除成功");
				}
			});
			layer.close(1);
		});
	}

	$("#searchBt").click(function() {
		example.ajax.reload();
	});

	function buttonAssociateFarm(href, permission, pers) {
		if(permission != "") {
			if($.inArray(permission, pers) < 0) {
				return "";
			}
		}
		var btn = $("<button class='layui-btn layui-btn-xs' title='关联基地' onclick='window.location=\"" + href + "\"'><i class='layui-icon'>&#xe642;</i></button>");
		return btn.prop("outerHTML");
	}
	init();
</script>

<script type="text/javascript">
	$(function() {
		// alert(1)
		// myconfirm()
		// myconfirm('保存成功！','husbandry_list.html');
		$('.warp').on('click', '.code', function() {
			layer.open({
				title: '您可以直接通过微信扫码登录',
				content: '<div id="qrcode" class="qrcode"></div>',
				offset: '100px',
				shadeClose: true
			});
			var id = $(this).parent().parent().children().eq(0).text();
			console.log(id)
			var farmid = localStorage.getItem('farmid')
			/*var url = 'http://x.topwulian.com:8080/mobile_producter/index.html?id=' + id + '&farmid=' + farmid;*/
			var url = 'http://x.topwulian.com/mobile_producter/index.html?id=' + id + '&farmid=' + farmid;
			var width=100;
			var height=100;
			//console.log(document.body.clientWidth);
			if(document.body.clientWidth>1000){
			    width=360
			}else if (document.body.clientWidth>=414) {
			    width=250
			}else{
			    width=100
			}
			var qrcode = new QRCode(document.getElementById("qrcode"), {
				width,
				height: width,
				text: url
			});
		})
	})
</script>